<template>
  <!-- 添加账号页 -->

  <div class="maxBox">
    <!-- 标题组件 -->
    <panel title="添加账号">
      <!-- 内容 -->
      <div class="content">
        <el-form ref="form" :model="form" label-width="80px">
          <el-form-item label="账号">
            <el-input v-model="form.account"></el-input>
          </el-form-item>

          <el-form-item label="密码">
            <el-input type="password" v-model="form.password"></el-input>
          </el-form-item>

          <el-form-item label="用户组">
            <el-select v-model="form.userGroup" placeholder="请选择用户组">
              <el-option label="超级管理员" value="超级管理员"></el-option>
              <el-option label="普通管理员" value="普通管理员"></el-option>
            </el-select>
          </el-form-item>

          <el-form-item>
            <el-button type="primary" @click="addBtn()"> 立即添加</el-button>
            <el-button @click="clear()">取消</el-button>
          </el-form-item>
        </el-form>
      </div>
    </panel>
  </div>
</template>

<script>
// 导入公共标题组件
import Panel from "../../components/Panel.vue";
import { userAdd } from "@/api/user.js";

export default {
  data() {
    return {
      form: {
        account: "",
        password: "",
        userGroup: "",
      },
    };
  },
  // 注册组件
  components: {
    Panel,
  },

  methods: {
    async addBtn() {
      //rule---element自定义验证规则
      let res = await userAdd(this.form);
      if (res.data.code === 0) {
        setTimeout(() => {
          //添加成功之后跳转到 账号列表页
          this.$router.push("/account-list");
        }, 1000);
      }
    },

    // 取消按钮 清空input
    clear() {
      (this.form.account = ""),
        (this.form.password = ""),
        (this.form.userGroup = "");
    },
  },
};
</script>

<style lang="less" scoped>
.maxBox {
  width: 100%;
  height: 100%;

  .contentBox {
    margin: 15px auto 0 auto;
    height: 400px;
    width: 97%;
    background: #fff;

    .title {
      width: 100%;
      height: 50px;
      line-height: 50px;
      padding-left: 15px;
      border-bottom: 2px solid rgb(233, 233, 233);
    }
  }
}

.accNum {
  display: flex;
  margin-left: 75px;
  width: 330px;
  line-height: 66px;

  p {
    width: 99px;
    line-height: 66px;
  }
}

.pwd {
  display: flex;
  margin-left: 75px;
  margin-top: 5px;
  width: 330px;
  line-height: 66px;

  p {
    width: 99px;
    line-height: 66px;
  }
}

// 用户组
.userZ {
  display: flex;
  margin-left: 75px;
  margin-top: 5px;
  width: 330px;
  line-height: 66px;

  p {
    width: 76px;
    line-height: 66px;
  }
}

.tjBtn {
  margin-top: 20px;
  margin-left: 150px;
}

.el-select {
  width: 89%;
}
</style>
